[DX-974] Fix commands --help documentation and json logging#181
[DX-974] Fix commands --help documentation and json logging#181
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughUpdated CLI help texts and examples across commands (channels, queues, rooms, integrations, auth), adjusted examples for channels annotations, added argument validation in base command parse, made openUrl optionally emit JSON, adjusted ChatClient logging behavior, extended channel metrics display, and added/updated unit tests for validation and JSON logging. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| FLAGS | ||
| -v, --verbose Output verbose logs | ||
| --cipher=<value> Decryption key for encrypted messages (AES-128) | ||
| --direction=<option> [default: backwards] Direction of message retrieval (default: backwards) |
There was a problem hiding this comment.
No need to show default twice in help methods
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/utils/open-url.ts (1)
14-43:⚠️ Potential issue | 🟡 MinorOnly
src/commands/status.tsneeds updating for consistent JSON output.The
isJsonOutputparameter implementation insrc/utils/open-url.tsis correct. However,src/commands/status.tssupports the--jsonflag and should pass it toopenUrl()at line 90:await openUrl("https://status.ably.com", this, this.shouldOutputJson(flags));Without this change, users running
status --json --openwill receive colored text mixed with JSON output, breaking parsers.src/commands/support/contact.tsdoes not support--jsonand does not require updating.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/utils/open-url.ts` around lines 14 - 43, The status command currently calls openUrl(...) without forwarding the JSON output flag, causing mixed colored text in JSON mode; update the call to openUrl in the status command to pass this.shouldOutputJson(flags) as the third argument so it becomes openUrl(..., this, this.shouldOutputJson(flags)) and ensure the import/use of openUrl and shouldOutputJson(flags) are correctly referenced (openUrl function and the command's shouldOutputJson method).
🧹 Nitpick comments (2)
src/commands/channels/annotations/delete.ts (1)
26-31: Consider updating the type argument description to match new examples.The
typeargument description still referencesreactions:flag.v1, reactions:multiple.v1, but the new examples usereceipts:flag.v1,categories:distinct.v1,reactions:unique.v1, andrating:multiple.v1. Consider updating the description to reflect the broader set of annotation types.📝 Suggested update
type: Args.string({ description: - "The annotation type (e.g., reactions:flag.v1, reactions:multiple.v1)", + "The annotation type (e.g., receipts:flag.v1, reactions:unique.v1, rating:multiple.v1)", required: true, }),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/channels/annotations/delete.ts` around lines 26 - 31, Update the description text for the Args.string argument named "type" in delete.ts to reflect the new example annotation types; replace the old examples ("reactions:flag.v1, reactions:multiple.v1") with the current examples such as "receipts:flag.v1, categories:distinct.v1, reactions:unique.v1, rating:multiple.v1" so the description accurately represents the broader set of supported annotation types.src/commands/channels/annotations/publish.ts (1)
26-31: Consider updating the type argument description to match new examples.Similar to
delete.ts, thetypeargument description still referencesreactions:flag.v1, reactions:multiple.v1, but the examples now usemetrics:total.v1,receipts:flag.v1,categories:distinct.v1,reactions:unique.v1, andrating:multiple.v1.📝 Suggested update
type: Args.string({ description: - "The annotation type (e.g., reactions:flag.v1, reactions:multiple.v1)", + "The annotation type (e.g., metrics:total.v1, receipts:flag.v1, rating:multiple.v1)", required: true, }),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/commands/channels/annotations/publish.ts` around lines 26 - 31, Update the description of the `type` argument inside the Args.string(...) call in publish.ts to reflect the current examples instead of the old reactions examples; specifically replace the example list with the new annotation types used elsewhere (e.g., metrics:total.v1, receipts:flag.v1, categories:distinct.v1, reactions:unique.v1, rating:multiple.v1) so the `type` Arg description matches delete.ts and the rest of the codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/channels/list.ts`:
- Around line 16-25: The ChannelMetrics interface declares objectPublishers and
objectSubscribers while the test mock in list.test.ts and the OccupancyMetrics
type (used in channels/occupancy/get.ts) do not — confirm whether the Ably
channel enumeration API actually returns these fields; if it does not, remove
objectPublishers and objectSubscribers from ChannelMetrics and any related
checks, and ensure OccupancyMetrics and test mocks in list.test.ts reflect the
same shape; if it does return them, add those fields to OccupancyMetrics and
update the mock data in list.test.ts (and any other affected tests) so
interfaces and tests match the real API.
---
Outside diff comments:
In `@src/utils/open-url.ts`:
- Around line 14-43: The status command currently calls openUrl(...) without
forwarding the JSON output flag, causing mixed colored text in JSON mode; update
the call to openUrl in the status command to pass this.shouldOutputJson(flags)
as the third argument so it becomes openUrl(..., this,
this.shouldOutputJson(flags)) and ensure the import/use of openUrl and
shouldOutputJson(flags) are correctly referenced (openUrl function and the
command's shouldOutputJson method).
---
Nitpick comments:
In `@src/commands/channels/annotations/delete.ts`:
- Around line 26-31: Update the description text for the Args.string argument
named "type" in delete.ts to reflect the new example annotation types; replace
the old examples ("reactions:flag.v1, reactions:multiple.v1") with the current
examples such as "receipts:flag.v1, categories:distinct.v1, reactions:unique.v1,
rating:multiple.v1" so the description accurately represents the broader set of
supported annotation types.
In `@src/commands/channels/annotations/publish.ts`:
- Around line 26-31: Update the description of the `type` argument inside the
Args.string(...) call in publish.ts to reflect the current examples instead of
the old reactions examples; specifically replace the example list with the new
annotation types used elsewhere (e.g., metrics:total.v1, receipts:flag.v1,
categories:distinct.v1, reactions:unique.v1, rating:multiple.v1) so the `type`
Arg description matches delete.ts and the rest of the codebase.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fcf6833d-8de8-4c2c-977b-ddad643091b4
📒 Files selected for processing (12)
README.mdsrc/commands/channels/annotations/delete.tssrc/commands/channels/annotations/index.tssrc/commands/channels/annotations/publish.tssrc/commands/channels/annotations/subscribe.tssrc/commands/channels/history.tssrc/commands/channels/inspect.tssrc/commands/channels/list.tssrc/commands/channels/subscribe.tssrc/commands/queues/create.tssrc/commands/rooms/messages/history.tssrc/utils/open-url.ts
| EXAMPLES | ||
| $ ably queues create --name "my-queue" | ||
|
|
||
| $ ably queues create --name "my-queue" --ttl 3600 --max-length 100000 |
There was a problem hiding this comment.
We are showing max values for both ttl and max-length, so updated to
ably queues create --name "my-queue" --ttl 300 --max-length 5000
There was a problem hiding this comment.
Pull request overview
This PR addresses DX-974 by aligning CLI --help/README documentation (examples and flag descriptions) with current command behavior, and additionally adjusts how URL-opening output is emitted in JSON mode.
Changes:
- Updates multiple command flag descriptions/examples to improve
--helpaccuracy (channels history/subscribe, rooms messages history, queues create, annotations commands). - Enhances
channels listoutput to show additional occupancy metrics when present. - Introduces JSON-mode handling for
openUrl()and wires it intochannels inspect.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/open-url.ts | Adds optional JSON output path when printing “Visit/Opening …” messages. |
| src/commands/rooms/messages/history.ts | Tweaks --order flag help text for clarity. |
| src/commands/queues/create.ts | Updates examples and revises --max-length/--ttl help text to mention maxima. |
| src/commands/channels/subscribe.ts | Clarifies cipher key encoding and delta compression help text. |
| src/commands/channels/list.ts | Adds optional display of additional occupancy metrics (object/presence subscribers/publishers). |
| src/commands/channels/inspect.ts | Passes JSON-mode indicator into openUrl(). |
| src/commands/channels/history.ts | Fixes examples and refines direction flag description. |
| src/commands/channels/annotations/subscribe.ts | Refreshes examples to match current annotation types/usage. |
| src/commands/channels/annotations/publish.ts | Refreshes examples to match current annotation types/usage. |
| src/commands/channels/annotations/index.ts | Updates topic-level examples for annotations. |
| src/commands/channels/annotations/delete.ts | Refreshes delete examples to match current annotation types/usage. |
| README.md | Regenerates/updates rendered help sections to match command example/flag text changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| '$ ably channels annotations delete my-channel "01234567890:0" "reactions:multiple.v1" --name thumbsup', | ||
| '$ ably channels annotations delete my-channel "01234567890:0" "reactions:flag.v1" --json', | ||
| '$ ably channels annotations delete my-channel "01234567890:0" "reactions:flag.v1" --pretty-json', | ||
| '$ ably channels annotations delete my-channel "01234567890:0" "receipts:flag.v1"', |
There was a problem hiding this comment.
--name isn't required for reactions:flag.v1 and reactions:total.v1
4313865 to
9c2e8a7
Compare
9c2e8a7 to
be142e9
Compare
397827f to
c30ec2f
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/channels/history.ts`:
- Around line 89-108: The progress/JSON "fetching" emission is happening before
buildHistoryParams(flags) which can throw, so move the block that calls
shouldOutputJson(), logJsonEvent(...) and the human log(formatProgress(...)) to
after the call to buildHistoryParams(flags); specifically, keep
buildHistoryParams(flags) where it is but relocate the entire "Show fetching
status" block (the calls to shouldOutputJson, logJsonEvent, log, formatProgress,
formatResource, and use of flags/channelName) to immediately after
buildHistoryParams returns so we only emit the fetching status when
historyParams was successfully constructed.
- Around line 50-53: The --direction flag currently omits the default from the
help text; update the Flags.string call for the direction flag (the property
named direction) so its description includes the default, e.g. change
description to "Direction of message retrieval (default: backwards)" or
"Direction of log retrieval (default: backwards)" while keeping options
["backwards","forwards"] so the help output matches the repo docs.
In `@src/commands/channels/publish.ts`:
- Line 56: The help text for the --delay option claims "max 25 msgs/sec" but
there is no enforcement; either remove the "max 25 msgs/sec" wording from the
description string for the --delay option or add a validator that enforces delay
>= 40ms (or equivalent rate limit) where the option is parsed/validated (look
for the --delay description string and the option/variable name delay in the
publish command implementation) and provide a clear error message when the user
supplies a value that would exceed 25 msgs/sec.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2a87f9bf-62f2-4d4f-b19d-c78d51d1b000
📒 Files selected for processing (26)
AGENTS.mdREADME.mdsrc/base-command.tssrc/chat-base-command.tssrc/commands/auth/issue-ably-token.tssrc/commands/auth/issue-jwt-token.tssrc/commands/channels/annotations/delete.tssrc/commands/channels/annotations/index.tssrc/commands/channels/annotations/publish.tssrc/commands/channels/annotations/subscribe.tssrc/commands/channels/history.tssrc/commands/channels/inspect.tssrc/commands/channels/list.tssrc/commands/channels/publish.tssrc/commands/channels/subscribe.tssrc/commands/integrations/create.tssrc/commands/queues/create.tssrc/commands/rooms/list.tssrc/commands/rooms/messages/history.tssrc/commands/rooms/messages/send.tssrc/commands/rooms/occupancy/get.tssrc/utils/open-url.tstest/unit/commands/channels/history.test.tstest/unit/commands/channels/publish.test.tstest/unit/commands/rooms/messages/history.test.tstest/unit/commands/rooms/messages/send.test.ts
✅ Files skipped from review due to trivial changes (12)
- src/commands/auth/issue-ably-token.ts
- src/commands/rooms/messages/history.ts
- src/commands/channels/annotations/subscribe.ts
- src/commands/integrations/create.ts
- src/commands/channels/annotations/index.ts
- AGENTS.md
- src/commands/auth/issue-jwt-token.ts
- src/commands/channels/annotations/publish.ts
- src/commands/queues/create.ts
- src/commands/channels/subscribe.ts
- src/commands/channels/annotations/delete.ts
- README.md
🚧 Files skipped from review as they are similar to previous changes (2)
- src/commands/channels/inspect.ts
- src/utils/open-url.ts
c30ec2f to
f9813f0
Compare
b326422 to
4e10e3e
Compare
4e10e3e to
40a687c
Compare
40a687c to
f9a5cfd
Compare
f9a5cfd to
06c979f
Compare
|
Updated the code, removed |
src/commands/channels/inspect.ts
Outdated
| await openUrl(url, this); | ||
| const isJson = this.shouldOutputJson(flags); | ||
| if (isJson) { | ||
| this.logJsonResult({ message: `Opening ${url} in your browser` }, flags); |
There was a problem hiding this comment.
how would this work for agents using the cli in --json mode?
There was a problem hiding this comment.
It shows
> bin/run.js channels inspect demo --pretty-json
{
"type": "result",
"command": "channels:inspect",
"success": true,
"message": "Opening https://ably.com/accounts/DIBHRw/apps/Sh_lKw/channels/demo in your browser"
}
There was a problem hiding this comment.
my question was more around the behaviour...
I pulled this down and tested it and an LLM/agent also opens the url automatically... I don't think we should do this?
The agent has access to the url in the response and can choose to open it if needed but I don't think we should try forcing the url open in json mode.
An example of where this would break would be if the CLI is running in some headless environment e.g. CI, or some agent nested in a headless multi-agent pipeline... this command would either fail silently or it would throw an error around their not being a browser to use.
I'd advocate against auto-opening urls in --json modes. Should be simple enough to guard this behaviour solely for non-json usage
There was a problem hiding this comment.
Okay, I was considering scenario where users might like to run commands in json mode for better data visibility. Seems, they can also do it manually by looking at the URL. So, will address 👍
06c979f to
fea0de7
Compare
- Fixed compile issues in presence get and presence subscribe
fea0de7 to
998d8b6
Compare
f58f4b5 to
b048ad7
Compare
src/commands/channels/subscribe.ts
Outdated
| "cipher-mode": Flags.string({ | ||
| default: "cbc", | ||
| description: "Cipher mode to use", | ||
| "Decryption key for encrypted messages (base64-encoded or hex-encoded), uses AES-256-CBC by default", |
There was a problem hiding this comment.
this doesn't read well... 128 vs 256 is determined by the value the user sets for this flag, so a "default" isn't really accurate here?
something like "Decryption key for encrypted messages (base64-encoded or hex-encoded, supports AES-128-CBC and AES-256-CBC)" would make more sense
| } | ||
|
|
||
| // openUrl opens a browser window if we're running normally, but just prints that it will if we're testing. | ||
| // In web CLI mode it prints "Visit <url>" instead of trying to open a browser. |
There was a problem hiding this comment.
the easier fix is to treat JSON mode like web cli mode...
this way you're guarding the behaviour in a lower level function instead of remembering the rule in every higher level implementation
There was a problem hiding this comment.
Yes, but it already prints normal log message
const openUrl = async (url: string, logger: Logger): Promise<void> => {
if (isWebCliMode()) {
logger.log(`${chalk.cyan("Visit")} ${url}`);
return;
}
We will need json check inside isWebCliMode() and this.logJsonResult isn't accessible in openUrl method. Since, openUrl isn't used at many placed, we can have external check for now wdyt
…and `cipher-mode` flags - Avoided opening url in browser in json mode
b048ad7 to
a5fdf07
Compare
--helpdoc for the commands, fixed description.Summary by CodeRabbit
Documentation
New Examples
User-facing Changes
Validation